package com.ipay.controller;

import com.ipay.bean.Order;
import com.ipay.bean.User;
import com.ipay.exception.IpayException;
import com.ipay.rpc.OrderPayAPI;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * @author ：前世小和尚（xiaopingzhang8@creditease.cn）
 * @Description ：
 * @ClassName ：HelloController
 * @Company ：普信恒业科技发展（北京）有限公司
 * @date ：2018/3/27 19:14
 */
//@RestController
@Controller
public class HelloController {

    @Resource
    private OrderPayAPI orderPayAPI;

    @RequestMapping("/")
    public String index(ModelMap map) {
        map.addAttribute("project", "springboot_ipay");
        return "index";
    }

    @RequestMapping("/sayhi")
    @ResponseBody
    public String sayHello() {
        return "hello world";
    }

    @RequestMapping("/submit")
    @ResponseBody
    public String submitOrder() {
        Order order = new Order("123", "123456", "OUT123456", "IN654321", new BigDecimal("34"));
        User user = new User("123", "zhangsan");
        return orderPayAPI.submitOrderUser(order, user);
    }

    @RequestMapping("/he")
    public String he() throws Exception {
        throw new Exception("哎呀，出错了");
    }

    @RequestMapping("/hehe")
    public String hehe() throws Exception {
        throw new IpayException("哎呀，出错了");
    }
}
